<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="详细信息"></uni-navbar></view>

		<view class="meeting-info">
			<view class="info-title">
				<view class="title-top">{{ hyhdMeeting.title }}</view>
				<view class="title-btm">
					<view class="btm-time" v-if="hyhdMeeting.startTime">{{ hyhdMeeting.startTime | parseTime('{y}-{m}-{d} {h}:{i}') }}--{{ hyhdMeeting.endTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</view>
					<text class="btm-address" v-if="hyhdMeeting.meetingAddress">{{ hyhdMeeting.meetingAddress }}</text>
				</view>
			</view>
		</view>

		<view class="container">
			<view class="rule-box">
				<view>会议安排：</view>
				<view v-html="hyhdMeeting.contentArrange"></view>
			</view>
			<view class="form-box form-box-show">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="开始时间">{{ hyhdMeeting.startTime }}</u-form-item>
					<u-form-item class="form-item" label="结束时间">{{ hyhdMeeting.endTime }}</u-form-item>
					<u-form-item class="form-item" label="组织部门" v-if="hyhdMeeting.remark2">{{ hyhdMeeting.remark2 }}</u-form-item>
				</u-form>
			</view>
			<view class="form-box" v-if="fileList.length > 0">
				<view class="file-list">
					<view>附件:</view>
					<view class="file-item" v-for="(item, index) in fileList" :key="index" @click="$showLine(item)">
						<view class="file-name clamp">{{ item.name }}</view>
						<view class="right-type">预览</view>
					</view>
				</view>
			</view>
			<view class="btn-box">
				<block v-if="['reg'].indexOf(hyhdMeeting.meetingState) != -1">
					<u-button class="form-btn" type="primary" v-if="remark4 == '0'" @click="queren">参会</u-button>
					<u-button class="form-btn" type="primary" v-if="remark4 == '1'">已确认</u-button>
					<u-button class="form-btn" type="info" v-if="remark4 != '2'" @click="qingjia">请假</u-button>
				</block>
				<block v-else><u-button class="form-btn" type="primary" v-if="remark4 == '1'" @click="navTo('/pagesB/meeting/affirm')">确认记录</u-button></block>
				<block v-if="['reg', 'reg_end'].indexOf(hyhdMeeting.meetingState) != -1">
					<u-button class="form-btn" type="info" v-if="hyhdMeeting.leaveApproveUser && remark4 == '2'" @click="navTo('/pagesB/meeting/leave')">请假记录</u-button>
					<u-button class="form-btn" type="info" v-if="!hyhdMeeting.leaveApproveUser && remark4 == '2'">已请假</u-button>
				</block>
				<block v-if="['going', 'end'].indexOf(hyhdMeeting.meetingState) != -1"><u-button class="form-btn" type="success" @click="navTo('/pagesB/meeting/sign')">签到记录</u-button></block>
				<block v-if="['reg_end', 'going', 'end'].indexOf(hyhdMeeting.meetingState) != -1"><u-button class="form-btn" type="warning" @click="navTo('/pagesB/meeting/plan')">会务安排</u-button></block>
				<u-button class="form-btn" type="error" v-if="hyhdMeeting.hasRicheng == '1'" @click="navTo('/pagesB/meeting/schedule')">日程安排</u-button>
			</view>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			hyhdMeeting: {
				title: '',
				startTime: '',
				endTime: '',
				hasRicheng: '',
				leaveApproveUser: '',
				remark2: '',
				remark4: '',
				meetingState: '',
				meetingAddress: '',
				contentArrange: ''
			},
			fileList: [],
			remark4: ''
		};
	},
	computed: {
		...mapState(['userInfo'])
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
		this.loadData();
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.userId = this.userInfo.sysUser.id;
				this.clientCode = this.userInfo.sysUser.clientCode;
			} else {
				this.$logout();
			}
		},
		queren() {
			this.$request('/huiyihuodong/hyhd-meeting-user/attendMeetingState?id=' + this.id + '&state=canhui&userId=' + this.userId).then((res) => {
				this.remark4 = '1';
				this.$msg('确认成功');
			});
		},
		qingjia() {
			if (!this.hyhdMeeting.leaveApproveUser) {
				this.$request('/huiyihuodong/hyhd-meeting-user/attendMeetingState?id=' + this.id + '&state=qingjia&userId=' + this.userId).then((res) => {
					this.remark4 = '2';
					this.$msg('申请成功');
				});
			} else {
				this.navTo('/pagesB/meeting/leave-add');
			}
		},
		loadData(id) {
			this.$request('/huiyihuodong/hyhd-meeting/query?id=' + this.id + '&curUserId=' + this.userId).then((res) => {
				this.fileList = res.data.fileList;
				// Object.assign(this.hyhdMeeting, res.data.hyhdMeeting)
				Object.keys(this.hyhdMeeting).forEach((key) => (this.hyhdMeeting[key] = res.data.hyhdMeeting[key]));
				if (!this.remark4) this.remark4 = this.hyhdMeeting.remark4;
			});
		},
		navTo(url) {
			if (!this.hyhdMeeting.meetingAddress) {
				this.hyhdMeeting.meetingAddress = '';
			}
			uni.navigateTo({
				url: url + '?id=' + this.id + '&name=' + this.hyhdMeeting.title + '&dept=' + this.hyhdMeeting.meetingAddress + '&time=' + this.hyhdMeeting.startTime
			});
		}
	}
};
</script>

<style lang="scss">
.u-btn {
	&--primary {
		background: #0099ff;
	}
	&--success {
		background: #18be6a;
	}
	&--info {
		background: #fe9900;
		border: 0;
		color: #fff;
	}
	&--warning {
		background: #ff5722;
	}
}

.info-box {
	padding: 30rpx 30rpx 100rpx;

	.info-title {
		margin-bottom: 14rpx;
	}
}

.rule-box {
	margin-bottom: 30rpx;
	padding: 30rpx;
	min-height: 200rpx;
	font-size: 16px;
	line-height: 60rpx;
	border-radius: 30rpx;
	background-color: #fff;

	.overflow {
		overflow: hidden;
	}
}

.form-box {
	margin-bottom: 30rpx;
	border-radius: 30rpx;
	background-color: #fff;

	.form-item {
		@include mp-flex;
	}
}

.btn-box {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;

	.form-btn {
		margin: 0 0 20rpx;
		width: 48%;
		font-size: 16px;
	}
}
</style>
